import types from '../types.js'
import axios from 'axios'
const state = {
    goods:[]
}

const getters = {   //拿到mutations里面的数据
    goods(state){
        return state.goods;
    }
}

const actions = {
    getGoods({commit,state}){
        axios.get('api/goods').then(resp => {
            if(resp.data.errno==0){
                commit(types.GET_GOODS,resp.data.data);
            }
        })
    }
}

const mutations = {
    [types.GET_GOODS](state,data){  //data是上面action传过来的数据
        state.goods = data;
    }
}

export default {
    state,
    getters,
    actions,
    mutations
}